package so.shanku.essential.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.*;
import aym.util.getservicesdata.GetServicesDataQueue;
import aym.util.getservicesdata.GetServicesDataUtil;
import aym.util.json.JsonMap;
import aym.util.json.JsonParseHelper;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.umeng.socialize.bean.SocializeConfig;
import com.umeng.socialize.sso.UMSsoHandler;
import net.tsz.afinal.annotation.view.ViewInject;
import so.shanku.essential.R;
import so.shanku.essential.activity.base.BaseUIActivity;
import so.shanku.essential.adapter.ProductPicAdapter;
import so.shanku.essential.adapter.RelationProductAdapter;
import so.shanku.essential.app.MyApplication;
import so.shanku.essential.getdata.GetDataConfing;
import so.shanku.essential.getdata.GetDataQueue;
import so.shanku.essential.getdata.JsonKeys;
import so.shanku.essential.getdata.ShowGetDataError;
import so.shanku.essential.utils.*;
import so.shanku.essential.view.BadgeView;
import so.shanku.essential.view.CircleImageView;
import so.shanku.essential.view.InsideViewPager;
import striveen.util.used.view.view.gridview.PLA_AdapterView;
import striveen.util.used.view.view.gridview.XGridView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Jaelyn on 2015/9/10.
 * 商品详情
 */
public class ProductDetailActivity extends BaseUIActivity implements PLA_AdapterView.OnItemClickListener {

    @ViewInject(id = R.id.only_webView)
    private ScrollView only_webView_layout;

    /**
     * 动画的imageview
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.iv_anim_collection)
    private ImageView iv_anim_collection;

    @com.lidroid.xutils.view.annotation.ViewInject(R.id.no_pic_iv)
    private ImageView no_pic_iv;//没有图片时 占位显示
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.home_goods_pic_vp)
    private InsideViewPager home_goods_pic_vp; //商品的图片

    /**
     * 剩余商品数量
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.goods_retain_tv)
    private TextView goods_retain_tv;
    /**
     * 刷新图下第一行
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.goods_discribe_tv)
    private TextView goods_discribe_tv;
    /**
     * 刷新图下第二行
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.goods_feature_discribe_tv)
    private TextView goods_feature_discribe_tv;

    /**
     * 现价
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.current_price_tv)
    private TextView current_price_tv;
    /**
     * 查看详情
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.promotion_tv)
    private TextView promotion_tv;

    /**
     * 原价
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.original_price_tv)
    private TextView original_price_tv;

    /**
     * 商品评论
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.goods_comments_layout)
    private LinearLayout goods_comments_layout;
    /**
     * 查看所有评论
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.scan_all_comments_tv)
    private TextView scan_all_comments_tv;

    /**
     * 评论提示
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.goods_comments_tv)
    private TextView goods_comments_tv;


    /**
     * 是否分享（收藏人数旁）
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.share_iv)
    private TextView share_iv;


    /**
     * 收藏人数
     */
    @ViewInject(id = R.id.collect_tv, click = "collect_tv_click")
    private TextView collect_tv;
    /**
     * 联系客服
     */
    @ViewInject(id = R.id.custom_service_tv, click = "custom_service_tv_click")
    private TextView custom_service_tv;

    /**
     * 加入购物车
     */
    @ViewInject(id = R.id.add_cart_tv, click = "add_cart_tv_click")
    private TextView add_cart_tv;
    /**
     * 立即购买
     */
    @ViewInject(id = R.id.instance_buy_tv, click = "instance_buy_tv_click")
    private TextView instance_buy_tv;


    @com.lidroid.xutils.view.annotation.ViewInject(R.id.relation_goods_layout)
    private LinearLayout relation_goods_layout;

    @ViewInject(id = R.id.gridview_product_detail)
    private XGridView gridview_product_detail;

    /**
     * 头部view
     */
    private View viewHead;
    /**
     * 下拉刷新Gridview适配器
     */
    private RelationProductAdapter productDetailAdapter;

    /**
     * 商品图片展示图
     */
    private ProductPicAdapter productPicAdapter;

    @com.lidroid.xutils.view.annotation.ViewInject(R.id.view_ind_layout)
    private LinearLayout view_ind_layout;     //指示器

    private LinearLayout linearLayout;  //head container

    /**
     * 用户头像
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.user_photo_iv)
    private CircleImageView user_photo_iv;
    /**
     * 用户名
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.userName_tv)
    private TextView userName_tv;

    /**
     * 评论内容
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.userComments_tv)
    private TextView userComments_tv;

    @com.lidroid.xutils.view.annotation.ViewInject(R.id.create_time_tv)
    private TextView create_time_tv;

    /**
     * 评论中 商品尺码 颜色
     */
    @com.lidroid.xutils.view.annotation.ViewInject(R.id.goods_color_size_tv)
    private TextView goods_color_size_tv;


    private String goods_id;//商品id
    private String vendorId;//商家Id
    private String catorgaryId;//商品类别
    private JsonMap goodsDatas;
    private int collectionNum;//收藏个数
    private List<JsonMap<String, Object>> datas;
    private int currentPage = 0;
    private int pageSize = 10;
    private List<JsonMap<String, Object>> productPics;//商品图片集合
    private BadgeView shopping_cart_badge;//购物车

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail);
        setCenter_title(R.string.app_name);
        setCartShopping();
        gridview_product_detail.setOnItemClickListener(this);
        gridview_product_detail.setPullRefreshEnable(false);
        gridview_product_detail.setPullLoadEnable(true);
        linearLayout = new LinearLayout(this);
        productPicAdapter = new ProductPicAdapter(mContext);
        addHead();
        goods_id = getIntent().getStringExtra(Constant.ID);
        productDetailAdapter = new RelationProductAdapter(this);
        productDetailAdapter.setShowDiscri(true);
        gridview_product_detail.setAdapter(productDetailAdapter);
        gridview_product_detail.setXListViewListener(loadMoreListener);
        getGoodsDetial();
    }


    @Override
    protected void onRestart() {
        super.onRestart();
        getShopCartNum();
    }

    //设置头部右上角购物车
    public void setCartShopping() {
        setBtn_menu(R.drawable.shopping_cart_lightgray, shoppingClick);
        shopping_cart_badge = new BadgeView(this, btn_menu);
        shopping_cart_badge.setTextSize(10);
    }

    private int shoppingCartNum = 1;
    //购物车的点击事件
    View.OnClickListener shoppingClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (shoppingCartNum == 0) {
                toast.showToast(R.string.shoppingCart_null);
            } else {
                jumpTo(ShopCartActivity.class);
            }
        }
    };

    //购物车接口
    private void getShopCartNum() {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        params.put("UserAccount", Utils.getUserAccount(this));
        GetDataQueue queue = new GetDataQueue();
        queue.setCallBack(callBack);
        queue.setActionName(GetDataConfing.GetAction_GetShoppingCartCount);
        queue.setWhat(GetDataConfing.What_GetShoppingCartCount);
        queue.setParamsNoJson(params);
        getDataUtil.getData(queue);
    }

    public void refreshShoppingCartNum() {
        shoppingCartNum = MyApplication.getInstance().getShopcart_num();
        if (shoppingCartNum > 99) {
            shopping_cart_badge.setText("...");
            shopping_cart_badge.show();
        } else if (shoppingCartNum == 0) {
            shopping_cart_badge.hide();
        } else {
            shopping_cart_badge.setText("" + shoppingCartNum);
            shopping_cart_badge.show();
        }

    }

    private XGridView.IXListViewListener loadMoreListener = new XGridView.IXListViewListener() {
        @Override
        public void onRefresh() {
        }

        @Override
        public void onLoadMore() {
            getRelationGoods();
        }
    };

    /**
     * 获取商品详情    * {Id:15973}
     */
    private void getGoodsDetial() {
        loadingToast.show();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        if (Utils.isHasLogin(this)) {
            params.put("UserName", Utils.getUserAccount(this));
        }
        params.put("Id", goods_id);
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_GetProductDetails);
        queue.setParamsNoJson(params);
        queue.setCallBack(callBack);
        queue.setWhat(GetDataConfing.What_GetProductDetails);
        getDataUtil.getData(queue);
    }


    /**
     * 获取相关商品  {VendorId:165,CategoryId:1535,currentPage:1,pageSize:10}
     */
    private void getRelationGoods() {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_Str);
        params.put("currentPage", currentPage + 1);
        params.put("pageSize", pageSize);
        params.put("VendorId", vendorId);
        params.put("CategoryId", catorgaryId);
        params.put("ProuctId", goods_id);
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_GetProudctCategroyList);
        queue.setParamsNoJson(params);
        queue.setCallBack(callBack);
        queue.setWhat(GetDataConfing.What_GetProudctCategroyList);
        getDataUtil.getData(queue);

    }

    /**
     * 添加头部控件
     */
    public void addHead() {
        viewHead = getLayoutInflater().inflate(R.layout.head_product_detail, null);

        gridview_product_detail.addHeaderView(linearLayout);
        ViewUtils.inject(this, viewHead);
        //home_goods_pic_vp.setNestedpParent((ViewGroup)home_goods_pic_vp.getParent());
    }
    /**
     * 分享的点击事件
     *
     * @param view
     */
    @OnClick(R.id.scan_all_comments_tv)
    public void scan_all_comments_tv_click(View view) {
        Intent intent=new Intent(mContext, GoodsCommentsActivity.class);
        intent.putExtra(Constant.ID,goods_id);
        jumpTo(intent,false);
    }

    /**
     * 分享的点击事件
     *
     * @param view
     */
    @OnClick(R.id.share_iv)
    public void share_iv_click(View view) {
        JsonMap jsonMap_temp = goodsDatas;
        String shareLogo = ((JsonMap) jsonMap_temp.getList_JsonMap("ProductPicList").get(0)).getStringNoNull("Path");
        String shareTitle = jsonMap_temp.getStringNoNull("SalesName");
        String shareContent = jsonMap_temp.getStringNoNull("describe");
        String shareUrl = "Product/Index?productId=" + goods_id;

        MyApplication.getInstance().showShareCompont(this, shareLogo, shareUrl, shareTitle, shareContent);
    }

    /**
     * 联系客服
     *
     * @param view
     */
    public void custom_service_tv_click(View view) {
        seeShopThemeDetail(vendorId);
    }
    /**
     * 收藏的点击事件
     *
     * @param view
     */
    public void collect_tv_click(View view) {
        changeGoodsCollect(goods_id, callBack);
    }

    /**
     * 加入购物车的点击事件
     *
     * @param view
     */
    public void add_cart_tv_click(View view) {
        if (goodsDatas == null) {
            return;
        }
        int stock = goodsDatas.getInt("Stock");
        if (stock < 1) {
            toast.showToast(R.string.product_sales_over);
            return;
        }
        boolean isShelves = goodsDatas.getBoolean("IsShelves");
        if (!isShelves) {
            toast.showToast(R.string.product_off_shelf);
            return;
        }
        String goodsName = goodsDatas.getStringNoNull("SalesName");

        if (goodsDatas.getList_JsonMap("SpecLst").isEmpty()) {
            add2Cart(goods_id, goodsName);
        } else {
            String json_str = goodsDatas.getString("SpecLst");

            Intent intent = new Intent(this, SelectGoodsParamsActivity.class);
            Bundle bundle = new Bundle();
            bundle.putInt(ExtraKeys.Key_Msg1, goodsDatas.getInt("IsSelectStock"));
            bundle.putString(Constant.COLOR_JSON_STR, json_str);
            bundle.putString(Constant.ID, goods_id);
            bundle.putString(Constant.NAME, goodsName);
            bundle.putString(Constant.GOODS_PRICE, goodsDatas.getStringNoNull("Price"));
            intent.putExtra(Constant.BUNDLE_EXTRA, bundle);
            this.startActivityForResult(intent, Constant.SELECT_COLOR_SIZE);
            overridePendingTransition(R.anim.push_bottom_in, R.anim.push_bottom_out);
        }

    }

    /**
     * 不选规格直接添加
     */
    private void add2Cart(String goodsId, String goodsName) {
        loadingToast.show();
        loadingToast.update(R.string.add2cart_ing);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(GetDataQueue.Params_key, GetDataConfing.Key_AddShoppingCart);
        params.put("UserAccount", Utils.getUserAccount(this));
        params.put("proId", goodsId);
        params.put("proName", goodsName);

        params.put("speStr", "");//sizeId+","+colorId);
        params.put("Amount", 1);
        GetDataQueue queue = new GetDataQueue();
        queue.setActionName(GetDataConfing.GetAction_AddShoppingCart);
        queue.setParamsNoJson(params);
        queue.setCallBack(callBack);
        queue.setWhat(GetDataConfing.What_AddShoppingCart);
        getDataUtil.getData(queue);
    }

    /**
     * 店铺logo的点击事件
     *
     * @param view
     */
    @OnClick(R.id.brandLogo_iv)
    public void brandLogo_iv_click(View view) {
        seeShopThemeDetail(vendorId);
    }


    /**
     * 查看详情的点击事件
     *
     * @param view
     */
    public void scan_detail_tv_click(View view) {
        Intent intent = new Intent(this, ProductAfterMarketDescActivity.class);
        intent.putExtra(ExtraKeys.Key_Msg1, goods_id);
        intent.putExtra(ExtraKeys.Key_Msg2, goodsDatas.getStringNoNull("ShopName"));
        startActivity(intent);

    }

    @Override
    public void onResume() {
        super.onResume();
        refreshShoppingCartNum();
    }

    private GetServicesDataUtil.IGetServicesDataCallBack callBack = new GetServicesDataUtil.IGetServicesDataCallBack() {

        @Override
        public void onLoaded(GetServicesDataQueue entity) {
            if (entity.isOk()) {
                if (ShowGetDataError.isCodeSuccess(mContext, entity.getInfo())) {
                    if (entity.what == GetDataConfing.What_GetProudctCategroyList) {
                        stopload();
                        List<JsonMap<String, Object>> data_server = JsonParseHelper.getJsonMap_List_JsonMap(entity.getInfo(), JsonKeys.Key_Info);
                        setData(data_server);
                        validateData(data_server);
                    } else if (entity.what == GetDataConfing.What_GetShoppingCartCount) {  //获取购物车数据
                        int num = JsonParseHelper.getJsonMap_List_JsonMap(entity.getInfo(),
                                JsonKeys.Key_Info).get(0).getInt("Count");
                        MyApplication.getInstance().setShopcart_num(num);
                        refreshShoppingCartNum();
                    } else if (entity.what == GetDataConfing.What_AddShoppingCart) {//添加购物车
                        JsonMap<String, Object> data = JsonParseHelper
                                .getJsonMap(entity.getInfo());
                        String msg = data.getString(JsonKeys.Key_Msg);
                        toast.showToast(msg);
                        MyApplication.getInstance().addShopCartNum();
                        refreshShoppingCartNum();
                    } else if (entity.what == GetDataConfing.What_GetProductDetails) {
                        goodsDatas = JsonParseHelper.getJsonMap_List_JsonMap(entity.getInfo(), JsonKeys.Key_Info).get(0);
                        refreshGoodsDetail();
                    } else if (entity.what == GetDataConfing.What_productAddUserAttention) { //收藏商品
                        JsonMap<String, Object> data = JsonParseHelper
                                .getJsonMap(entity.getInfo());
                        try {
                            String msg = data.getString(JsonKeys.Key_Msg);
//						toast.showToast(msg);
                            if (msg.equals(getString(R.string.programe_like_s))) {
                                updateCollectionStatues(true);
                                startAnimation();

                                //homePageRefreshAdapter.setStatuesChange(itemPosition, true);

                                //jsonMap.put()
                            } else if (msg.equals(getString(R.string.programe_like_n))) {
                                //removeFavourtePrograme(programId);

                                //homePageRefreshAdapter.setStatuesChange(itemPosition, false);
                                updateCollectionStatues(false);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    if (entity.what == GetDataConfing.What_GetProudctCategroyList) {
                        stopload();
                    }
                }
            } else {
                if (entity.what == GetDataConfing.What_GetProudctCategroyList) {
                    stopload();
                }
                ShowGetDataError.showNetError(mContext);
            }
            loadingToast.dismiss();
        }

    };

    private void updateCollectionStatues(boolean b) {

        collect_tv.setSelected(b);
//        if (b) {
//            collectionNum++;
//        } else {
//            collectionNum--;
//        }
//        collect_tv.setText("" + collectionNum);
    }

    private void startAnimation() {
        Animation animout = AnimationUtils.loadAnimation(this, R.anim.zoom_exit);
        iv_anim_collection.setVisibility(View.VISIBLE);
        iv_anim_collection.startAnimation(animout);
        animout.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv_anim_collection.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }

    /**
     * 设置商品信息 并请求相关商品的信息
     */
    private void refreshGoodsDetail() {
        if (TextUtils.isEmpty(goodsDatas.getStringNoNull("MoreAndProduct")) || "0".equalsIgnoreCase(goodsDatas.getStringNoNull("MoreAndProduct"))) {
            only_webView_layout.removeAllViews();
            linearLayout.removeAllViews();
            only_webView_layout.addView(viewHead);

            only_webView_layout.setVisibility(View.VISIBLE);
            gridview_product_detail.setVisibility(View.GONE);
        } else {
            only_webView_layout.removeAllViews();
            linearLayout.removeAllViews();
            linearLayout.addView(viewHead);
            only_webView_layout.setVisibility(View.GONE);
            gridview_product_detail.setVisibility(View.VISIBLE);
        }
        productPics = goodsDatas.getList_JsonMap("ProductPicList");
        if (productPics.size() != 0) {
            no_pic_iv.setVisibility(View.GONE);
            home_goods_pic_vp.setVisibility(View.VISIBLE);
            productPicAdapter = new ProductPicAdapter(this, productPics);
            productPicAdapter.setOnItemClickListener(new ProductPicAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(int position, int index) {
                    goodsImage_click(position, index % productPics.size());
                }
            });
            productPicAdapter.setIndContainerView(view_ind_layout);
            home_goods_pic_vp.setAdapter(productPicAdapter);
            home_goods_pic_vp.setCurrentItem(productPics.size() * 100);

            home_goods_pic_vp.setOnPageChangeListener(productPicAdapter);
        } else {
            no_pic_iv.setVisibility(View.VISIBLE);
            home_goods_pic_vp.setVisibility(View.GONE);
        }
        setCenter_title(goodsDatas.getStringNoNull("ShopName"));

        boolean isShelves = goodsDatas.getBoolean("IsShelves");
        if (!isShelves) {
            goods_retain_tv.setVisibility(View.VISIBLE);
            goods_retain_tv.setText(R.string.salve_over);
            MyApplication.getInstance().startAnimation(goods_retain_tv);
        } else {
            int stock = goodsDatas.getInt("Stock");
            if (stock < 4) {
                goods_retain_tv.setVisibility(View.VISIBLE);
                if (stock < 1) {
                    goods_retain_tv.setText(R.string.salve_over);
                    MyApplication.getInstance().startAnimation(goods_retain_tv);
                } else {
                    String strFormat = this.getString(R.string.product_retain);
                    String goods_retain_str = String.format(strFormat, stock + "");
                    goods_retain_tv.setText(goods_retain_str);
                    MyApplication.getInstance().startAnimation(goods_retain_tv);
                }
            } else {
                goods_retain_tv.setVisibility(View.INVISIBLE);
            }

        }
        goods_discribe_tv.setText(goodsDatas.getStringNoNull("SalesName"));
        goods_feature_discribe_tv.setText(goodsDatas.getStringNoNull("describe"));

        current_price_tv.setText(StringUtil.getFormatMoneyWithSign(goodsDatas.getStringNoNull("Price")));
        original_price_tv.setText(StringUtil.getFormatMoneyWithSign(goodsDatas.getStringNoNull("Price")));

        create_time_tv.setVisibility(View.GONE);
        //collectionNum = Integer.parseInt(goodsDatas.getStringNoNull("UserAttentionCount"));//FocusOnNum
        //collect_tv.setText("" + collectionNum);
        collect_tv.setSelected(goodsDatas.getBoolean("IsAttention", false));

//        String brandLogoPath = goodsDatas.getStringNoNull("brandLogo");
//        if (MyApplication.getInstance().getBitmapHashMap().containsKey(brandLogoPath)) {
//            brandLogo_iv.setImageBitmap((MyApplication.getInstance().getBitmapHashMap().get(brandLogoPath)));
//        } else {
//            ImageLoader.getInstance().displayImage(brandLogoPath, brandLogo_iv, MyApplication.getInstance().getBrandDefaultOption(), new ImageLoaderBitmapCallBack());
//        }

        vendorId = goodsDatas.getStringNoNull("VendorId");
        catorgaryId = goodsDatas.getStringNoNull("CategoryId");
        if (TextUtils.isEmpty(goodsDatas.getStringNoNull("MoreAndProduct")) || "0".equalsIgnoreCase(goodsDatas.getStringNoNull("MoreAndProduct"))) {
            //toast.showToast(R.string.no_relation_goods_data);
            relation_goods_layout.setVisibility(View.GONE);
        } else {
            gridview_product_detail.setBoolInterceptTouchEvent(true);
            getRelationGoods();
            relation_goods_layout.setVerticalGravity(View.VISIBLE);
        }
    }

    private void setData(List<JsonMap<String, Object>> data_server) {

        if (currentPage == 0) {
            datas = data_server;
            productDetailAdapter.setDatas(data_server);
            gridview_product_detail.setAdapter(productDetailAdapter);

        } else {
            datas.addAll(data_server);
            productDetailAdapter.notifyDataSetChanged();
        }
        currentPage++;
    }

    private void setRefreshStatus(boolean isCanPull) {
        //programs_grid.setPullRefreshEnable(isCanRefresh);
        //programs_grid.setPullLoadEnable(isCanPull);
        gridview_product_detail.setPullLoadEnable(isCanPull); //下拉刷新
        //gridview_product_detail.setFootMsg("");
    }

    /**
     * 校验数据 显示无数据等
     * <p/>
     * 是否请求正常 网络错误且数据为空的话显示网络异常界面 提供刷新的接口
     *
     * @param data_server
     */
    private void validateData(List<JsonMap<String, Object>> data_server) {
        if (data_server.size() == 0 || data_server.size() % pageSize != 0) {
            setRefreshStatus(false);
//			if (datas.size() == 0) {
//				toast.showToast(R.string.no_relation_goods_data);
//			} else {
//				//toast.showToast(R.string.xlistview_footer_hint_no_more);
//			}
        }
    }

    private void stopload() {
        gridview_product_detail.stopLoadMore();
    }

    @Override
    public void onItemClick(PLA_AdapterView<?> parent, View view, int position, long id) {
        if (position >= 2) {
            JsonMap map = datas.get(position - 2);
            String goods_id = map.getStringNoNull("ProductId");
            seeProductDetail(goods_id);
        }
    }


    /**
     * 商品图片的点击 进入大图
     *
     * @param picPosition
     * @param itemPosition
     */
    private void goodsImage_click(int itemPosition, int picPosition) {
        String pic_jsonStr = goodsDatas.getStringNoNull("ProductPicList");//图片的集合
        Bundle bundle = new Bundle();
        bundle.putString(Constant.IMAGE_JSON_STR, pic_jsonStr);
        bundle.putInt(Constant.IMAGE_POSITION, picPosition);
        jumpTo(ShowBigImageActivity.class, bundle, false);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**使用SSO授权必须添加如下代码 */
        UMSsoHandler ssoHandler = SocializeConfig.getSocializeConfig().getSsoHandler(requestCode);
        if (ssoHandler != null) {
            ssoHandler.authorizeCallBack(requestCode, resultCode, data);
        }
//		UMSocialService umSocialService=MyApplication.getInstance().getmController();
//		if(umSocialService!=null) {
//			UMSsoHandler ssoHandler =umSocialService.getConfig().getSsoHandler(requestCode);
//			if (ssoHandler != null) {
//				ssoHandler.authorizeCallBack(requestCode, resultCode, data);
//			}
//		}
    }
}
